package my;

import my.mvc.ActionCallback;
import my.mvc.RequestContext;
import site.hackway.Init;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;

/**
 * Created by hackway on 2016/5/15.
 */
public class init {
    public static void main(String[] args) {
        String root = RequestContext.class.getResource("/").getFile();
        System.out.println(root);
        File file = new File(root);
        try {
            System.out.println(new File(root).getParentFile().getParentFile().getCanonicalPath());
        } catch (IOException e) {
            e.printStackTrace();
        }
        Init inits = new Init();
        if (inits instanceof ActionCallback) {
            System.out.println("instance true");
        }
        System.out.println(inits.getClass().getName());
        Set<String> cls = getClassNameFromDir(root,"",true);
        for (String str:cls) {
            System.out.println(str);
        }

    }

    public static Set<String> getClassNameFromDir(String filePath, String packageName,boolean isRecursion) {
        Set<String> className = new HashSet<>();
        File file = new File(filePath);
        File[] files = file.listFiles();
        if (files!=null) {
            for (File childFile : files) {
                if (childFile.isDirectory()) {
                    if (isRecursion) {
                        className.addAll(getClassNameFromDir(childFile.getPath(), packageName + "." + childFile.getName(), isRecursion));
                    }
                } else {
                    String fileName = childFile.getName();
                    if (fileName.endsWith(".class") && !fileName.contains("$")) {
                        className.add(packageName + "." + fileName.replace(".class", ""));
                    }
                }
            }
        }
        return className;
    }


}
